<?php 
/**
 * 公用控制器
 */
class CommonController extends Controller{
	/**
	 * 初始化函数
	 */
	public function __init(){
		
	}
	/**
	 * 公用导航分类
	 */
	protected function category(){
		    $c_model = K('Category');
        $c_data = $c_model->where("pid=0")->all(); 
        // p($c_data);
        // 循环顶级分类，重组数组,把子集压入进去
        foreach ($c_data as $k => $cate) {
        	$c_data[$k]['son'] = $c_model->where("pid='{$cate['cid']}'")->all();
            foreach ($c_data[$k]['son'] as $key => $value) {
                $c_data[$k]['son'][$key]['son'] = $c_model->where("pid='{$value['cid']}'")->all();
            }
           	if(isset($c_data[$k]['son'][1]['son'][1])){
           		 $c_data[$k]['cate_s'][1] =$c_data[$k]['son'][1]['son'][1];
           		}else{
           			$c_data[$k]['cate_s'][1] = array();
           		}
           

        }
        // p($c_data);
        $this->assign('c_data',$c_data);
        //品牌分类
        $brand_data = K('Brand')->all();
        // p($brand_data);
        $this->assign('b_data',$brand_data);
        // 顶级导航分配
        $this->assign('top_c_data',$c_model->where("pid=0")->all()); 
	}

  //根据当前cid递归获得商品的分类，存入数组
  protected function path($cid){
    static $path = array();
    $data = M('category')->where(array('cid' => $cid))->getField('cid,cname,pid');
    $path[$data[$cid]['cid']] = $data[$cid]['cname'];
    if($data[$cid]['pid'] != 0){
      $this->path($data[$cid]['pid']);
    }
    return $path;
  }

  // 云台热卖商品
  protected function hot(){
    // 云台热卖随机顺序调取
    $rand_data = M('goods')->order('rand()')->limit(3)->getField('gid,gname,pic,goods_price,type_tid');
    $this->assign('rand_data',$rand_data);
  }


}













 ?>